package com.example.demo01;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import sun.security.smartcardio.SunPCSC;

import javax.swing.*;
import java.beans.Customizer;
/*
    构建初始化项目官网地址：https://start.spring.io/
 */
@SpringBootApplication
public class Demo01Application {
    public static void main(String[] args) {
        //SpringApplication.run(Demo01Application.class, args);
        WebServerApplicationContext context = (WebServerApplicationContext) SpringApplication.run(Demo01Application.class, args);
        int port = context.getWebServer().getPort();
        System.out.println("应用程序正在运行，端口号：" + port);
    }


    // 默认端口8080，自定义端口9999
    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
        return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
            @Override
            public void customize(ConfigurableWebServerFactory factory) {
                factory.setPort(9999);  // 设置自定义的端口号
            }
        };
    }

}
